<?php
require_once '../aop/AopClient.php';
require_once '../aop/AopCertClient.php';
require_once '../aop/AopCertification.php';
require_once '../aop/AlipayConfig.php';
require_once '../aop/request/AlipayFundAuthOrderAppFreezeRequest.php';

// 初始化SDK
$alipayClient = new AopClient(getAlipayConfig());
// 构造请求参数以调用接口
$request = new AlipayFundAuthOrderAppFreezeRequest();
$model = array();

// 设置后付费项目
$postPayments = array();
$postPayments0 = array();
$postPayments0['amount'] = "0.01";
$postPayments0['name'] = "租金";
$postPayments0['description'] = "2元/小时，99元封顶";
$postPayments[] = $postPayments0;
$model['post_payments'] = $postPayments;

// 设置订单标题
$model['order_title'] = "XX租车押金";

// 设置需要冻结的金额
$model['amount'] = "0.01";

// 设置收款账户的支付宝用户号
$model['payee_user_id'] = "2088102000275795";

// 设置商户授权资金订单号
$model['out_order_no'] = "8077735255938023";

// 设置销售产品码
$model['product_code'] = "PREAUTH_PAY";

// 设置收款账户的支付宝登录号（email或手机号）
$model['payee_logon_id'] = "159****5620";

// 设置无特殊需要请勿传入
$model['enable_pay_channels'] = "[{\"payChannelType\":\"PCREDIT_PAY\"},{\"payChannelType\":\"MONEY_FUND\"}]";

// 设置商户指定的结算币种
$model['settle_currency'] = "USD";

// 设置免押受理台模式
$model['deposit_product_mode'] = "POSTPAY";

// 设置预授权订单相对超时时间
$model['pay_timeout'] = "2d";

// 设置标价币种
$model['trans_currency'] = "USD";

// 设置无特殊需要请勿传入
$model['identity_params'] = "{\"identity_hash\":\"acc2b92ffc5ed9b472faa19748f10045c30434132784f774b00216a56b8841c6\"}";

// 设置业务参数
$model['business_params'] = "{\"outRiskInfo\":\"{\"mcCreateTradeTime\":\"2022-03-11 12:46:09\",\"extraAccountCertnoLastSix\":\"000011\",\"mobileOperatingPlatform\":\"ios\",\"sysVersion\":\"15.4.2\",\"mcCreateTradeIp\":\"11.110.111.43\"}\"}";

// 设置预授权订单相对超时时间
$model['timeout_express'] = "2d";

// 设置无特殊需要请勿传入
$model['disable_pay_channels'] = "[{\"payChannelType\":\"OPTIMIZED_MOTO\"},{\"payChannelType\":\"BIGAMOUNT_CREDIT_CARTOON\"}]";

// 设置场景码
$model['scene_code'] = "OVERSEAS_ONLINE_AUTH_COMMON_SCENE";

// 设置商户本次资金操作的请求流水号
$model['out_request_no'] = "8077735255938032";

// 设置业务扩展参数
$model['extra_param'] = "{\"category\":\"CHARGE_PILE_CAR\",\"serviceId\":\"2020042800000000000001450466\"}";

$request->setBizContent(json_encode($model,JSON_UNESCAPED_UNICODE));
$orderStr = $alipayClient->sdkExecute($request);
echo $orderStr;

function getAlipayConfig()
{
    $privateKey  = '<-- 请填写您的应用私钥，例如：MIIEvQIBADANB ... ... -->';
    $alipayPublicKey = '<-- 请填写您的支付宝公钥，例如：MIIBIjANBg... -->';
    $alipayConfig = new AlipayConfig();
    $alipayConfig->setServerUrl('https://openapi.alipay.com/gateway.do');
    $alipayConfig->setAppId('<-- 请填写您的AppId，例如：2019091767145019 -->');
    $alipayConfig->setPrivateKey($privateKey);
    $alipayConfig->setFormat('json');
    $alipayConfig->setAlipayPublicKey($alipayPublicKey);
    $alipayConfig->setCharset('UTF-8');
    $alipayConfig->setSignType('RSA2');
    return $alipayConfig;
}